/*
 *  BC_Utils.m
 *  CocOth
 *
 *  Created by BrunoCausse on 03/11/10.
 *  Copyright 2010-2013 poulailler cie. All rights reserved.
 *
 */


#import "BC_Utils.h"


@implementation BC_Utils

/*
 from secondes (float) to string DD:HH:MM:SS.cc
 */
+ (NSString *)toHMS:(float)secondes
{
	int sign = -1;
	
	int t = (int)(secondes*100);
	
	if (t < 0) {t = -t;} else sign = +1;
	int d = t / 8640000; t -= d * 8640000LL;
	int h = t / 360000; t -= h * 360000;
	int m = t / 6000; t -= m * 6000;
	int s = t / 100; t -= s * 100;
	int c = t;
	
	if (d) return [NSString stringWithFormat:@"%2d:%02d:%02d:%02d.%02d", sign*d, h, m, s, c];
	else if (h) return [NSString stringWithFormat:@"   %2d:%02d:%02d.%02d", sign*h, m, s, c];
	else return [NSString stringWithFormat:@"      %2d:%02d.%02d", sign*m, s, c];
}


/*
 from hexaString to unsigned long long
 */
+ (unsigned long long)stringToHexa:(NSString *)aString
{
	NSString *sValue = [NSString stringWithFormat:@"0x%@", aString];
	
	unsigned long long hValue = 0x0ull;
	if ([[NSScanner scannerWithString:sValue] scanHexLongLong:&hValue]) {
		return hValue;
	}
	
	NSLog(@"ERROR: stringToHexa convertion failed");
	
	return hValue;
}

@end